//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    motto: 'Hello Worker',
  },
  onLoad: function () {
    // 文件名指定 worker 的入口文件路径，绝对路径
    const worker = wx.createWorker('/workers/request/index.js');
    //向Worker线程发送的消息
    worker.postMessage({
      msg: '来自于主线程的消息'
    });
    //监听Worker线程向当前线程发送的消息的事件
    var that = this
    worker.onMessage(function(res){
      var resValue = res.msg
      console.log('------------------------------------------')
      console.log('这是主线程打印的')
      console.log(resValue) //打印res对象里的属性成员变量的值
      that.setData({  //绑定数据
        motto:resValue
      })
    });
    // worker.terminate()
  },

    
})
